package com.ywk.base.javaBase.hashCode;

import org.openjdk.jol.vm.VM;

import java.util.ArrayList;

/**
 * @Author zbh
 * @Date 2023/1/31
 */
public class HashCodeTest {
    public static void main(String[] args) {
        Object obj = new Object();
        long address = VM.current().addressOf(obj);
        long hashCode = obj.hashCode();
        System.out.println("before GC : The memory address is " + address);
        System.out.println("before GC : The hash code is " + hashCode);
        new Object();
        new Object();
        new Object();
        System.gc();
        long afterAddress = VM.current().addressOf(obj);
        long afterHashCode = obj.hashCode();
        System.out.println("after GC : The memory address is " + afterAddress);
        System.out.println("after GC : The hash code is " + afterHashCode);
        System.out.println("---------------------");
        System.out.println("memory address = " + (address == afterAddress));
        System.out.println("hash code = " + (hashCode == afterHashCode));

        ArrayList<String> a = new ArrayList<>();
        Integer integer = new Integer(111);
        System.out.println(integer.hashCode());
//        integer.equals()

    }
}

